﻿$(function () {
    var currentPage = 0;
    var mycommentTotlaPage = $("#mycommentTotlaPage").html();
    contrlPageNumberDisplay();
    /*-------------分页---------------*/
    //控制页码是否显示
    function contrlPageNumberDisplay() {
        $('#currentPage').html(currentPage + 1);
        //当处于首页的时候,'上一页'隐藏
        if (currentPage == 0) {
            $('#previousPage').hide();
        }
        else {
            $('#previousPage').show();
        }
        //当处于末页的时候,'下一页'隐藏
        if (currentPage == (mycommentTotlaPage - 1)) {
            $('#nextPage').hide();
        }
        else {
            $('#nextPage').show();
        }
    }

          
    //首页
    var $fristPage = $("#fristPage");
    $fristPage.click(function (e) {
        $.get("MyCommentAjaxRequest?pageIndex=0", function (data) {
            currentPage = 0;
            $('#myCommentList').empty();
            $('#myCommentList').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //上一页
    var $previousPage = $("#previousPage");
    $previousPage.click(function (e) {
        $.get("MyCommentAjaxRequest?pageIndex=" + (currentPage - 1), function (data) {
            currentPage = currentPage - 1;
            $('#myCommentList').empty();
            $('#myCommentList').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //下一页
    var $nextPage = $("#nextPage");
    $nextPage.click(function (e) {
        $.get("MyCommentAjaxRequest?pageIndex=" + (currentPage + 1), function (data) {
            currentPage = currentPage + 1;
            $('#myCommentList').empty();
            $('#myCommentList').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    //末页
    var $lastPage = $("#lastPage");
    $lastPage.click(function (e) {
        $.get("MyCommentAjaxRequest?pageIndex=" + (mycommentTotlaPage - 1), function (data) {
            currentPage = mycommentTotlaPage - 1;
            $('#myCommentList').empty();
            $('#myCommentList').html(data);//替换成新的数据
            contrlPageNumberDisplay();
        });
    });

    var fancyOption = {
        maxWidth: 1000,
        maxHeight: 600,
        fitToView: true,
        wrapCSS: 'custom-fancy-wrapper',
        helpers: {
            overlay: {
                css: {
                    'background': 'rgba(255,255,255,.6)'
                },
                closeClick: false
            }
        },
        tpl: {
            closeBtn: '<i class="fa fa-times"></i>'
        },
        autoSize: true
    };

    $('#viewMycomment').fancybox(fancyOption);
});